package com.example.finalsystem.Controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.example.finalsystem.Service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GoodsController {
//    仓库管理员添加删除修改查看物品
    @Autowired
    GoodsService goodsService;

    @ResponseBody
    @PostMapping("/goods/addGoods")
    public String addGoods(@RequestParam String goodsName, @RequestParam int goodsNumber,@RequestParam int threshold)
    {
        return  goodsService.addGoods(goodsName,goodsNumber,threshold);
    }

    @ResponseBody
    @PostMapping("/goods/fixGoods")
    public String fixGoods(@RequestParam String goodsName, @RequestParam int goodsNumber,@RequestParam int threshold)
    {
        return  goodsService.fixGoods(goodsName,goodsNumber,threshold);
    }


    @ResponseBody
    @PostMapping("/goods/deleteGoods")
    public String deleteGoods(@RequestParam String goodsName)
    {
        return  goodsService.deleteGoods(goodsName);
    }

    @ResponseBody
    @PostMapping("/goods/getGoods")
    public String getGoods(@RequestParam String goodsName)
    {
        return JSON.toJSONString( goodsService.getGoods(goodsName) );
    }

    @ResponseBody
    @PostMapping("/goods/getListOfGoods")
    public String getListOfGoods(@RequestParam int currentPage,@RequestParam int pageSize)
    {
        return JSONArray.toJSONString( goodsService.getListOfGoods(currentPage,pageSize) );
    }

    @ResponseBody
    @PostMapping("/goods/countGoods")
    public String countGoods()
    {
        return ""+ goodsService.countAll() ;
    }

}
